]> git.r.bdr.sh - rbdr/super-polarity/blobdiff - Super Polarity/ActorManager.cs
I think bullets come out now.
[rbdr/super-polarity] / Super Polarity / ActorManager.cs
index 39ae336f313121ea28964ea9854190a44e3a7009..1b4ef96c6e1c506a690a0b6c9899e782879d0287 100644 (file)
@@ -9,10 +9,14 @@ namespace SuperPolarity
 {
     static class ActorManager
     {
+
+        static Game Game;
+        static int OutlierBounds;
         static List<Actor> Actors;
 
         static ActorManager()
         {
+            OutlierBounds = 100;
             Actors = new List<Actor>();
         }
 
@@ -29,6 +33,7 @@ namespace SuperPolarity
         static public void Update(GameTime gameTime) 
         {
             CheckActors();
+            CheckOutliers();
             foreach (Actor actor in Actors)
             {
                 actor.Update(gameTime);
@@ -74,13 +79,33 @@ namespace SuperPolarity
                 var dx = other.Position.X - actor.Position.X;
                 var linearDistance = Math.Sqrt(Math.Pow(dx, 2) + Math.Pow(dy, 2));
                 var angle = (float) Math.Atan2(dy, dx);
+                var otherAngle = (float)Math.Atan2(-dy, -dx);
 
                 if (linearDistance < actor.MagneticRadius || linearDistance < other.MagneticRadius)
                 {
                     actor.Magnetize(other, (float)linearDistance, angle);
-                    other.Magnetize(actor, (float)linearDistance, 90 - angle);
+                    other.Magnetize(actor, (float)linearDistance, otherAngle);
                 }
             }
         }
+
+        static void CheckOutliers()
+        {
+            for (var i = Actors.Count; i > 0; i--)
+            {
+                var actor = Actors[i-1];
+                if (actor.Position.X < -OutlierBounds || actor.Position.Y < -OutlierBounds ||
+                    actor.Position.X > Game.GraphicsDevice.Viewport.Width + OutlierBounds ||
+                    actor.Position.Y > Game.GraphicsDevice.Viewport.Height + OutlierBounds)
+                {
+                    CheckOut(actor);
+                }
+            }
+        }
+
+        internal static void SetGame(Game game)
+        {
+            Game = game;
+        }
     }
 }